package ubadbtools.recoveryLogAnalyzer.redo.gui.forms;

import java.awt.Frame;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

import ubadbtools.recoveryLogAnalyzer.redo.common.RecoveryLog;
import ubadbtools.recoveryLogAnalyzer.redo.common.recoveryActions.*;
import ubadbtools.recoveryLogAnalyzer.redo.common.RecoveryResult;
import java.util.List;
import java.util.ListIterator;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class AnalyzeLogDialog extends JDialog
{
	//[start] Constructor
    public AnalyzeLogDialog(Frame parent, boolean modal, RecoveryLog log)
    {
    	super(parent, modal);
        initComponents();
        
        AnalyzeRecoverability(log);
    }
    //[end]
    
    //[start] showDialog
    public static void showDialog(Frame parent, RecoveryLog log)
    {
    	AnalyzeLogDialog dialog = new AnalyzeLogDialog(parent, true, log);
        dialog.setVisible(true);
    }
    //[end]
    
    //[start] AnalyzeRecoverability
    public void AnalyzeRecoverability(RecoveryLog log)
    {
    	RecoveryResult pasos = log.recoverFromCrash();
    	List<RecoveryAction> lactions=pasos.getRecoveryActions();
    	ListIterator<RecoveryAction> liter=lactions.listIterator();
    	while (liter.hasNext())
    	{
    		resultados.append( liter.next().toString() );
    		resultados.append("\n");
    	}
    	
    	
    }
    //[end]

    //[start] ShowErrorMessage
	/**
     * Muestra un mensaje de error al usuario
     * @param message
     */
	public void ShowErrorMessage(String message)
	{
		JOptionPane.showConfirmDialog(
			this,
			message,
			"Error",
			JOptionPane.DEFAULT_OPTION,
			JOptionPane.ERROR_MESSAGE);
	}
	//[end]
	
    //[start] InitComponents (AUTO-GENERATED)
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        butCerrar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        resultados = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        tituloResultados = new javax.swing.JLabel();

        this.setTitle("Análisis de log");
        setLocationByPlatform(true);

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        butCerrar.setText("Cerrar");
        butCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butCerrarActionPerformed(evt);
            }
        });
        jPanel1.add(butCerrar);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 10));
        jPanel2.setPreferredSize(new java.awt.Dimension(500, 400));
        jPanel2.setLayout(new java.awt.BorderLayout());

        resultados.setColumns(20);
        resultados.setEditable(false);
        resultados.setLineWrap(true);
        resultados.setRows(5);
        jScrollPane1.setViewportView(resultados);

        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel3.setLayout(new java.awt.BorderLayout(0, 5));

        tituloResultados.setText("Resultado");
        jPanel3.add(tituloResultados, java.awt.BorderLayout.PAGE_END);

        jPanel2.add(jPanel3, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents
	//[end]
    
    //[start] Eventos
    private void butCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butCerrarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_butCerrarActionPerformed
	//[end]
	
	//[start] Variables Form (AUTO-GENERATED)
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butCerrar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea resultados;
    private javax.swing.JLabel tituloResultados;
    // End of variables declaration//GEN-END:variables
    //[end]
}
